#include "common_wgt.h"
#include <QScreen>

double g_screenFactorX = 1.0;
double g_screenFactorY = 1.0;

//设置窗体、弹窗的边缘阴影
void setDialogShadow(QWidget *widget, QWidget *widgetShadow)
{
    widget->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    widget->setAttribute(Qt::WA_TranslucentBackground, true);
    QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(widget);
    shadow->setOffset(0, 0);                                                                            //设置阴影距离
    shadow->setColor(QColor("#444444"));                                                                //设置阴影颜色  #444444
    shadow->setBlurRadius(20);                                                                          //设置阴影圆角
    widgetShadow->setGraphicsEffect(shadow);                                                            //设置阴影

    QString name = widgetShadow->objectName();
    //设置一下样式表，否则子窗口也会跟着透明
    widgetShadow->setStyleSheet( QString("#%1{background:#f5f5f5;border-radius:5px;}").arg(name) );
}

//美化控件样式
void setCommonWidgetStyle(int widgetType,QWidget *widget)
{
    switch (widgetType)
    {
        case PushButton:
        {
            widget->setStyleSheet("QPushButton {border-image:url(:/new/icons/icons/play.png);background-color: rgb(18,150,219);"
                                "color: rgb(205, 233, 252);"
                                "border-radius:2px;"
                                "border:1px solid rgb(160, 160, 160);}"
                              "QPushButton::hover {background-color: rgb(29, 70, 179);}"
                              "QPushButton:pressed {border-image: url(:/new/icons/icons/play-pressed.png);}"
                              "QPushButton:disabled {color: #333333;}"
                              "QPushButton::menu-indicator image: none;}");

            break;
        }
        case LineEdit:
        {
            widget->setStyleSheet(QString("QLineEdit {padding-left:10px;padding-right:10px;"
                                      "background: #00356B;border: 1px solid #1183BF;}"
                                      "QLineEdit:focus{border:4px solid rgb(85,170,255);background-color:rgb(43,45,56);}"));
            break;
        }

    }
}

void moveWgtCenter(QPair<double,double>& movePoint,QWidget *wgt)
{
    QScreen *screen = QGuiApplication::screens().first();
    QRect mm = screen->geometry() ;
    int screen_width = mm.width();
    int screen_height = mm.height();

    double x = (screen_width - wgt->width())/2;
    double y = (screen_height - wgt->height())/2;
    movePoint = QPair<double,double>(x*g_screenFactorX,y*g_screenFactorY);

}
